package com.qlmy.cn.bean

import android.os.Parcelable
import com.contrarywind.interfaces.IPickerViewData
import com.squareup.moshi.Json
import kotlinx.android.parcel.Parcelize
import com.qlmy.cn.api.ApiCode
import com.qlmy.cn.commom.formatRetain


/**
 * 统一数据封装类
 */
data class ResultBean<T>(var success: Boolean = false,
                         var colName: Any? = null,
                         var code: Int = 0,
                         var msg: String? = null,
                         var content: T? = null,
                         var data: T? = null) {
    companion object {
        const val SUCCESS = 200
        const val NOT_LOGIN = 401 //未登录或登录失效
        const val SERVICE_ERROR = 500 //服务器内部错误
    }

    val isOk: Boolean
        get() = success || code == SUCCESS
}

data class ApiData(
        var apiCode: ApiCode = ApiCode.START,
        var data: Any? = null,
        var apiName: String? = null,
        var throwable: Throwable? = null,
)

//data class TabEntity(
//        var title: String? = "",
//        var selectedIcon: Int = 0,
//        var unSelectedIcon: Int = 0,
//        var tag: String? = null,
//        var extend: String? = null,
//) : CustomTabEntity {
//    override fun getTabUnselectedIcon() = unSelectedIcon
//    override fun getTabSelectedIcon() = selectedIcon
//    override fun getTabTitle() = title
//
//}
data class UserInfoBean(
        val gmtCreate: String = "",
        val gmtModified: String = "",
        val id: Int = 0,
        val paramId: Int = 0,
        val remarks: String = "",
        val roleId: Int = 0,
        val userAccount: String = "",
        val userName: String = "",
        val userPwd: String = "",
)

data class ImageUploadBean(
        var resId: Int = 0,
        var url: String? = null,
        var netUrl: String? = null,
        var originalFile: String = "",
        var md5: String? = null,
        var filePath: String? = null,
        var uploadFileName: String? = null,
        var position: Int = 0,
)

data class UploadDataBean(
        val originalFile: String = "",
        var compressFile: String = "",
)

data class PageBean<T>(
        val records: MutableList<T> = mutableListOf(),
        val total: Int = 0,
)

@Parcelize
data class OrgBean(
        @Json(name = "org_code") val orgCode: String = "",
        @Json(name = "org_name") val orgName: String = "",
) : IPickerViewData, Parcelable {
    override fun getPickerViewText() = orgName
}

@Parcelize
data class StoreCompanyBean(
        val id: Int = 0,
        val companyCode: String = "",
        val companyName: String = "",
        val creditCode: String = "",
) : IPickerViewData, Parcelable {
    override fun getPickerViewText() = companyName
}

data class StoreLocationBean(
        val kdmc: String = "",
        val kddm: String = "",
//        val kddz: String = "",
) : IPickerViewData {
    override fun getPickerViewText() = kdmc
}

data class ClauseBean(
        val id: Int = 0,
        val tkmc: String,
) : IPickerViewData {
    override fun getPickerViewText() = tkmc
}

enum class TableType {
    COLUMN_TITLE, GROUP, ROW_WHITE, ROW_GREY
}

enum class InventoryClassificationTopEnum(val title: String, val key: String) {
    SWXJ("库存实物小计", "swxj"),
    CITY_CC("禅城", "禅城区"),
    CITY_NH("南海", "南海区"),
    CITY_SD("顺德", "顺德区"),
    CITY_GM("高明", "高明区"),
    CITY_SS("三水", "三水区"),
    CITY_FLJT("佛粮集团", "佛粮集团"),
}

class StockMonthBean(private val map: Map<String, Any>) {
    val pzmc: String get() = map["pzmc"].toString().replace(" ", "")
    val pzxz: String get() = map["pzxz"].toString().replace(" ", "")
    val dwmc: String get() = map["dwmc"].toString().replace(" ", "")
    val zldw: String get() = map.get("zldw")?.toString() ?: ""
    operator fun get(key: String) = map[key]?.toString()?.toDouble()?.formatRetain() ?: "0.00"
}

data class TableDate(
        val name: String = "",
        val tableType: TableType = TableType.COLUMN_TITLE,
        val subTableDates: MutableList<TableDate>? = null
)

enum class RealTimeIinventoryTopEnum(val title: String, val key: String, val group: RealTimeIinventoryTopGroupEnum? = null) {
    DFRWY("地方储备任务(原粮)", "dfrwy"),
    DFRWCP("成品粮", "dfrwcp"),
    DFWCSJ("地方储备完成实绩(原粮)", "dfwcsj"),
    DFSJDM("实际大米", "dfsjdm"),
    DFSJMF("实际面粉", "dfsjmf"),
    DFWCL("完成计划%", "dfwcl"),
    DSRW("储备任务", "dsrw", RealTimeIinventoryTopGroupEnum.GROUP_DSRW),
    DSWCSJ("完成实绩", "dswcsj", RealTimeIinventoryTopGroupEnum.GROUP_DSRW),
    DSWCL("完成计划%", "dswcl", RealTimeIinventoryTopGroupEnum.GROUP_DSRW),
    DZYRW("储备任务", "dzyrw", RealTimeIinventoryTopGroupEnum.GROUP_DZYRW),
    DZYWCSJ("完成实绩", "dzywcsj", RealTimeIinventoryTopGroupEnum.GROUP_DZYRW),
    DZYWCL("完成计划%", "dzywcl", RealTimeIinventoryTopGroupEnum.GROUP_DZYRW),
    SYYRW("储备任务", "syyrw", RealTimeIinventoryTopGroupEnum.GROUP_SYYRW),
    SYYWCSJ("完成实绩", "syywcsj", RealTimeIinventoryTopGroupEnum.GROUP_SYYRW),
    SYYSJL("完成计划%", "syysjl", RealTimeIinventoryTopGroupEnum.GROUP_SYYRW),
}

enum class RealTimeIinventoryTopGroupEnum(val title: String) {
    GROUP_DSRW("代省储备(原粮)"),
    GROUP_DZYRW("代中央储备(原粮)"),
    GROUP_SYYRW("食用植物油储备"),
}
/*
data class Monster(
        val name1: String = "1",
        val name2: String = "1",
        val name3: String = "1",
        val name4: String = "1",
        val name5: String = "1",
        val name6: String = "1",
        val name7: String = "1",
        val tableType: TableType,
)

data class RealTimeIinventoryData(
        val name1: String = "1",
        val name2: String = "1",
        val name3: String = "1",
        val name4: String = "1",
        val name5: String = "1",
        val name6: String = "1",
        val name7: String = "1",
        val name8: String = "1",
        val name9: String = "1",
        val name10: String = "1",
        val name11: String = "1",
        val name12: String = "1",
        val name13: String = "1",
        val name14: String = "1",
        val name15: String = "1",
        val tableType: TableType,
)*/
